<extend name="Public/base" />
<!--test--->
<block name="body">
    <p class="" style="color:red;">本页订单，均为交易成功(状态为交易成功)的订单，受理/取消/未成功订单不计入总消费</p>
    <div class="data-table table-striped">
        <table class="">
            <tbody>
            <tr>
                <th>客户</th>
                <td>{$relation.realName}</td>
                <th>编号</th>
                <td id="uid">{$relation.id}</td>
            </tr>
            <tr>
                <th>联系电话</th>
                <td><input type="text"  style="height: 30px;width: 120px;" id="phone" name="phone" value="{$relation.phone}">&nbsp;&nbsp;<button class="btn btn-primary" id="phoneModify" style="height: 30px;">确认修改</button></td>
                <th>业务员</th>
                <td style="min-width: 120px;">
                    <input type="text" style="border:none;height: 30px;" id="sname" name="sname" value="{$relation.sname}">
                    <select id="salesList">
                        <option></option>
                        <volist name="sales" id="sale">
                            <option data-id="{$sale.id}" value="{$sale.name}">{$sale.name}</option>
                        </volist>
                    </select>
                </td>
            </tr>
            <tr>
                <th>总消费</th>
                <td style="font-size: 20px;color:red;font-weight: 700;"  >￥&nbsp;{$relation.sum|number_format=###,2}&nbsp;元</td>
                <th>余额</th>
                <td>
                    ￥{$relation.amount}元
                    <?php if(get_nickname()=='admin'){ ?>
                        <input type="number" id="amountSum" class="text input-small" placeholder="支持负数">
                        <input type="text" id="amountMark" class="text input-small" placeholder="备注">
                        <button class="btn btn-danger" id="changeAmount">！确认！</button>
                   <?php
                    }
                   ?>
                </td>
            </tr>
            <tr>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="data-table table-striped">
        <table class="table table-hover">
            <thead>
            <tr>
                <th style="width: 50px;">订单编号</th>
                <th style="min-width: 30px">总价</th>
                <th style="min-width: 80px;">状态</th>
                <th width="120px;">导出</th>
                <th style="width: 120px;">收货人</th>
                <th style="min-width:70px;">联系电话</th>
                <th width="400">收货地址</th>
                <th width="200">下单时间</th>
                <th width="200">操作</th>
            </tr>
            </thead>
            <tbody>
            <notempty name="orderLists">
                <volist name="orderLists" id="vo">
                    <tr  valign="top">
                        <td>{$vo.orderid} </td>
                        <td><span style="color: red;font-weight: bold;">{$vo.amount}</span> </td>
                        <td>{$vo.status_text} </td>
                        <if condition="($vo.is_export eq 1)">
                            <td>已导出</td>
                            <else />
                            <td>未导出</td>
                        </if>
                        <td>{$vo.toName} </td>
                        <td>{$vo.toPhone} </td>
                        <td style="max-width: 150px;">{$vo.toProvince}&nbsp;{$vo.toCity}&nbsp;{$vo.toArea}&nbsp;{$vo.toStreet}
                            <br/><span style="color: red;">{$vo.remark}</span>
                        </td>
                        <td>{$vo.createDate|time_format} </td>
                        <td style="min-width: 280px;">
                            <a href="{:U('Order/Orderdetails')}&orderid={$vo['orderid']}" class="btn btn-default">明细</a></td>
                    </tr>
                </volist>
                <else/>
                <td colspan="12" class="text-center"> aOh! 暂时还没有内容! </td>
            </notempty>
        </table>
    </div>
    <div class="page">
        {$_page}
    </div>
    <div class="text-center">
        <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
    </div>
    <!------左边E------>
    <style>

        .table2 tr th{
            background-color: #F5F5F5;
            font-size: 9px;
            font-weight: normal;
            border: 1px solid #000;
            padding-left: 5px;
        }
        .table2 tr td{
            border: 1px solid #000;
            padding-left: 5px;
            font-weight: bold;
        }
    </style>
</block>


<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U('Relation/index')}');
        var salesList = $("#salesList");
        var phone = $("#phone");
        var changePhone = $("#phoneModify");
        var changeAmount = $("#changeAmount");
        var url = '{:U('Relation/changeSname')}';
        var phoneUrl = '{:U('Relation/changePhone')}';
        var returnAmountUrl = '{:U('Relation/returnAmount')}';
        salesList.on("change",function(){
            if($("#salesList option:selected").val()==""){
                return false;
            }
            $("#sname").val($("#salesList option:selected").val());
            if(confirm("是否确认修改")){
                $.ajax({
                    url: url,
                    data: {sid:$("#salesList option:selected").data("id"),uid:$("#uid").text(),sname:$("#salesList option:selected").val()},
                    success: function(obj){
                        alert(obj);
                    }
                });
            }
        });
        changePhone.on("click", function () {
            if(confirm("确认修改？")){
                $.ajax({
                    url: phoneUrl,
                    data: {uid:$("#uid").text(),phone:phone.val()},
                    success: function(obj){
                        alert(obj);
                    }
                });
            }
        });
        changeAmount.on("click", function () {
             amountSum = $("#amountSum").val();
             amountMark = $("#amountMark").val();
            if(amountSum==undefined||amountSum==null||amountSum==""||amountMark==undefined||amountMark==null||amountMark==""){
//            alert(amountSum);
//            if(amountSum||amountMark){
                alert("金额或备注为空");
            }else{
                if(confirm("确定")){
                    if(confirm("真的确定吗？")){
                        $.ajax({
                            url: returnAmountUrl,
                            data: {uid:$("#uid").text(),amount:amountSum,mark:amountMark},
                            success: function(obj){
                                alert(obj);
                            },
                            error:function(){
                                alert($("#returnAmount option:selected").val());
                            }
                        });
                    }
                }
            }

        });

    </script>
</block>
